package com.icetec.iceintel.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.GridView;
import android.widget.TextView;

import com.icetec.R;
import com.icetec.iceintel.framework.IceBaseActivity;
import com.icetec.iceintel.ui.adapter.SelectDeviceGridViewAdapter;
import com.icetec.iceintel.utility.ToastUtility;

/**
 * Created by amo on 2015/3/12.
 * 选择一个灯具，然后通过onResult回传所选择的灯具的MAC地址
 */
public class SelectDeviceActivity extends IceBaseActivity {

    TextView backTv;
    TextView finishTv;
    GridView lightGirdView;
    SelectDeviceGridViewAdapter selectDeviceGridViewAdapter;

    final int SINGLE_DEVICE_SUCESS=1;



    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_selectdevice);


        backTv=(TextView)findViewById(R.id.activity_selectdevice_back);
        finishTv=(TextView)findViewById(R.id.activity_selectdevice_finish);

        lightGirdView=(GridView)findViewById(R.id.activity_selectdevice_gridview);


        backTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


        finishTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(selectDeviceGridViewAdapter.getSelectedDevice()==null){

                    ToastUtility.show(R.string.please_select_atlseat_once);
                    return;

                }

                Intent intent=new Intent();
                intent.putExtra("MAC",selectDeviceGridViewAdapter.getSelectedDevice().getMAC());
                setResult(SINGLE_DEVICE_SUCESS,intent);
                finish();
            }
        });

        selectDeviceGridViewAdapter=new SelectDeviceGridViewAdapter();
        lightGirdView.setAdapter(selectDeviceGridViewAdapter);


    }




}
